package org.example.创建型模式.抽象工厂模式.重构代码.Redis双集群升级_抽象工厂.factory;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * @author : hmxchen
 * @program : modules-api
 * @description :
 * @create : 2022-04-14 09:48
 **/
public class JDKProxy {
    public static <T> T getProxy(Class<T> interfaceClass, ICacheAdapter cacheAdapter){
        InvocationHandler handler = new JDKInvocationHandler(cacheAdapter);

        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        Class<?>[] classes = interfaceClass.getInterfaces();
        return (T) Proxy.newProxyInstance(classLoader, new Class[]{classes[0]}, handler);
    }

}
